<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>

<div class="header">
	<h2>
		绩效考核信息<span><font color="red">（* 为必填项）</font> </span>
	</h2>
</div>
<script type="text/javascript">
	var containUnscore = null;
	function cusAction(rowObject) {
		var sourceId = $("#id").val();
		var id = rowObject.id;
		return "<a class='nui-txt-link' onclick=addPreItemDetail('" + id + "')>评价</a>";
	}

	function addPreItemDetail(id) {
		isperp.openDialog({
			id : "addPreItemDetailDialog",
			windowSize : "normal",
			contentUrl : 'performance/performanceItemDetail/edit?pcontrolid=preItemDetailGrid&sourceId=' + id + '&id=' + id + '&type=1',
			title : "新增"
		});
	}
	function checkScore(cellvalue) {
		containUnscore = false;
		if (!cellvalue || cellvalue == null) {
			containUnscore = true;
			return "<span style='color:red'>未评价</span>";

		} else
			return cellvalue;
	}
	function LoadScore(data) {
		getTotalScore();
	}
	function getTotalScore() {
		var totalScore = 0;
		$("[id^='manager_score_']").each(function() {
			if ($(this).val() == "") {
				//ifIncludeUnScore = true;
			} else {
				var weight = $(this).data("weight");
				var selfScore = parseFloat($(this).val());
				totalScore += (selfScore / 150) * 150 * (weight / 100);
			}
		});
		$("#managerTotalScoreText").text(totalScore.toFixed(1));
		$("#managerTotalScore").val(totalScore.toFixed(1));
		var level = "E";
		if (totalScore >= 120 && totalScore < 140) {
			level = "B";
		} else if (totalScore >= 140) {
			level = "A";
		}else if(totalScore >= 100 && totalScore < 120)
		{
		   level = "C";
		}else if(totalScore >= 60 && totalScore < 100)
		{
		  level = "D";
		}
		//$("#perLevelManagerLb").text(level);
		//$("#perLevelManager").val(level);
	}
	function formatText(v) {
		if (v != null && v != "")
			return "<pre>" + v + "</pre>";
		else
			return "";
	}
	function updateText3(v) {
		return v + "%";
	}
	function updateText1(v, o, r, c) {
		containUnscore = false;
		var cellId = r.id;
		var weight = r.weight;
		if (v != null)
			return "<input id='" + c + "_" + cellId + "' class='perInput number' data-weight='" + weight + "' value='" + v + "' onchange=\"updateValue(this,'" + c + "','" + cellId + "',0)\"/>";
		else
			return "<input id='" + c + "_" + cellId + "' class='perInput number' data-weight='" + weight + "' onchange=\"updateValue(this,'" + c + "','" + cellId + "',0)\"/>";
	}
	function updateText2(v, o, r, c) {
		var cellId = r.id;
		if (v != null && v != "")
			//return "<pre>" + v + "</pre>";
			return "<textarea id='" + c + "_" + cellId + "' class='perInput1' onchange=\"updateValue(this,'" + c + "','" + cellId + "',1)\">" + v + "</textarea>";
		else
			return "<textarea id='" + c + "_" + cellId + "' class='perInput1' onchange=\"updateValue(this,'" + c + "','" + cellId + "',1)\"></textarea>";
	}
	function updateValue(obj, columnName, id, type) {
		var value = obj.value;
		var perUserSubmitId = $("#id").val();
		var score = $("#manager_score_" + id).val();
		if (type == 0) {
			if (/^(\+|-)?\d+($|\.\d+$)/.test(score)) {
				var tsc = parseFloat(score);
				if (tsc<0||tsc>150) {
					isperp.alert("请输入150分内的分值！");
					return false;
				}
			} else {
				isperp.alert("请输入数字！");
				return false;
			}
		}

		var managerEvaluate = $("#manager_evaluate_" + id).val();
		$.ajax({
			url : 'performance/performanceItemDetail/updateValue2',
			data : {
				"id" : id,
				"managerEvaluate" : managerEvaluate,
				"managerScore" : score,
				"perUserSubmitId" : perUserSubmitId
			},
			success : function(data) {
				getTotalScore();
			}
		});
	}
</script>
<style>
.ui-jqgrid-view .ui-jqgrid-bdiv td {
	white-space: nowrap;
	text-indent: 6px;
	text-overflow: initial;
	overflow: inherit;
	padding: 0px;
	font-size: 11px;
}

.perInput {
	height: 98%;
	width: 50%;
}

.perInput1 {
	height: 98%;
	width: 70%;
}

.textareaInput {
	white-space: normal;
	text-align: justify;
	-moz-text-align-last: center; /* Firefox 12+ */
	text-align-last: center;
}

.ui-jqgrid-bdiv {
	overflow: hidden;
}
</style>
<form:form commandName="model" cssClass="validate" id="performanceForm"
	action="performance/performance/save">
	<form:hidden path="id" />
	<div class="box" style="overflow: hidden">
		<isperp:processProcesser processId="${model.processId }"></isperp:processProcesser>
	</div>
	<table class=" form-table">
		<tbody>

			<tr>
				<td class="td1">被考核人：</td>
				<td class="td2">${model.perUserFullname }</td>

				<td class="td1">岗位：</td>
				<td class="td2"><form:input path="positionName"
						style="display:none" /> ${model.positionName }</td>
			</tr>

			<tr>
				<td class="td1">考核时间：</td>
				<td class="td2">
					<div id="dateSelector" style="display:inline-block;">
						${model.perYear }年${model.perMonth }月
				</td>

				<td class="td1">主管：</td>
				<td class="td2">${model.managerFullname }</td>
			</tr>
			<tr>
				<td class="td1">提交人评级：</td>
				<td class="td2">${model.perLevel}</td>
				<td class="td1">自评总分：</td>
				<td class="td2" colspan="3"><span id="selfTotalScore"
					style="color:red">${model.selfTotalScore}</span></td>
			</tr>
			<tr>
				<td class="td1">提交人自评：</td>
				<td class="td2" colspan="3"><pre>${model.selfDescription }</pre>
				</td>
			</tr>
			<tr>
				<td colspan="4">
					<div class="header">
						<h2>主管评价</h2>
					</div>
				<td>
			</tr>

			<tr>
				<td class="td1">评价等级：</td>
				<td class="td2">
					<select id="perLevelManagerLb" name="perLevelManager" class="required">
					  <option>A</option>
					  <option>B</option>
					  <option>C</option>
					  <option>D</option>
					  <option>E</option>
					</select>
					</td>

				<td class="td1">主管总评分：</td>
				<td class="td2" colspan="3"><span id="managerTotalScoreText"
					style="color:red"></span> <form:hidden path="managerTotalScore" />
				</td>
			</tr>
			<tr>
				<td class="td1">主管评价：</td>
				<td class="td2" colspan="3"><form:textarea
						path="managerDescription" cssClass="required"/></td>
			</tr>

			<tr>
				<td colspan="4">
					<div class="header">
						<h2>下一步审批人(如需下一步审批请选择)</h2>
					</div>
				<td>
			</tr>

			<tr>
				<td class="td1">审批人：</td>
				<td class="td2"><form:hidden path="lastApprover" /> <isperp:departmentUser
						displayValue="${model.lastApproverName }"
						parentIdControlId="8135359050480003" valueControlId="lastApprover"
						idFieldName="name" id="lastApproverName"
						ifIncludeNoRoleUser="false" name="lastApproverName"
						multiselect="false" displayValueCssClass=""></isperp:departmentUser>
				</td>
			</tr>

		</tbody>
	</table>
</form:form>
<div class="header">
	<h2>
		各项指标完成情况<span></span>
	</h2>
</div>
<isperp:grid
	url="performance/performanceItemDetail/listData?sourceId=${model.id }"
	gridId="preItemDetailGrid" showPager="false" showSearchbar="false"
	showToolbar="false" cusDialogSize="big" loadComplete="LoadScore(data);"
	cusActions="cusAction(rowObject)" cusFormatterActions="true">
	<jsp:body>
		<isperp:column name="id" title="id" hidden="true"></isperp:column>
	    <isperp:column name="name" title="指标名称"
			formatter="return formatText(cellvalue)" isFormatterFun="true"
			width="70"></isperp:column>
	    <isperp:column name="target" title="目标"
			formatter="return formatText(cellvalue)" isFormatterFun="true"
			width="160"></isperp:column>
	    <isperp:column name="referenc_point" title="衡量标准"
			formatter="return formatText(cellvalue)" isFormatterFun="true"
			width="160"></isperp:column>
	    <isperp:column name="weight" title="权重" width="50"
			formatter="return updateText3(cellvalue)" isFormatterFun="true"></isperp:column>
	    <isperp:column name="self_score" title="自评分" width="80"></isperp:column>
	    <isperp:column name="situation" title="自评价"
			formatter="return formatText(cellvalue)" isFormatterFun="true"
			width="70"></isperp:column>
	    <isperp:column name="manager_score" title="主管评分"
			isFormatterFun="true"
			formatter="return updateText1(cellvalue,options,rowObject,'manager_score')"
			width="60"></isperp:column>
	    <isperp:column name="manager_evaluate" title="主管评价"
			formatter="return updateText2(cellvalue,options,rowObject,'manager_evaluate')"
			isFormatterFun="true" width="90"></isperp:column>
	</jsp:body>
</isperp:grid>

<isperp:buttonList>
	<isperp:processButtons processKey="performanceProcess"
		beforeSubmit="function c(name){return beforeSubmit(name);}"
		processId="${model.processId }" businessKey="${model.id }"
		formId="performanceForm"></isperp:processButtons>
</isperp:buttonList>
<script type="text/javascript">
	function beforeSubmit(name) {
		getTotalScore();
		ifIncludeUnScore = false;
		$("[id^='manager_score_']").each(function() {
			if ($(this).val() == "") {
				ifIncludeUnScore = true;
			}
		});
		if (name == "结束审批") {
			if (ifIncludeUnScore) {
				isperp.alert("还有未评价的指标！");
				return false;
			} else {
				return true;
			}
		} else if (name == "提交下一步审批") {
			if ($("#lastApprover").val() == "") {
				isperp.alert("请选择下一步审批人！");
				return false;
			} else {
				return true;
			}
		} else {
			return true;
		}
	}
</script>

